<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>应急指挥辅助决策系统</title>
	<script src="../js/validation/prototype_for_validation.js" type="text/javascript"></script>
	<script src="../js/validation/effects.js" type="text/javascript"></script>
	<script src="../js/validation/validation_cn.js" type="text/javascript"></script>
	<script src="../js/validation/tooltips.js" type="text/javascript"></script>
	<script src="../js/jquery1.9.1.js" type="text/javascript"></script>
	<script src="../js/urlParams.js" type="text/javascript"></script>
	<script src="../js/ajaxfileupload.js" type="text/javascript"></script>
	<script src="../js/jquery.uploadify.js" type="text/javascript"></script>
	<script src="../js/iframeAuto.js" type="text/javascript"></script>
	<link rel="stylesheet" type="text/css" href="../styles/style_min.css" />
	<link href="../styles/edas_back.css" rel="stylesheet" type="text/css" />
	<link href="../styles/uploadify.css" rel="stylesheet" type="text/css" />
	<link href="../styles/tooltips.css" rel="stylesheet" type="text/css" />
	<style type="text/css">
		PRE {
			padding-top: 0px;
			padding-bottom: 0px;
			padding-left: 60px;
			padding-right: 10px;
			border-right: #cccccc 1px dashed;
			border-bottom: #cccccc 1px dashed;
			border-top: #cccccc 1px dashed;
			border-left-width: 0px;
			background:#fafafa url(images/codebg.jpg) repeat-y fixed 0 0;
			color: #4d87ce;
		}
	</style>
	
	
</head>
<body>
	<div id="mainContainer" style="Margin-Right: auto; Margin-Left: auto;"
		align="center">
		<form id="user_form_id" name="user_form">
			<table>
				<tr>
					<td width="60px">&nbsp;</td>
					<td align="left"><img id="head_pic_id" src="../images/youc.png" width="129px" height="129px"></td>
				</tr>
	
				<tr>
					<td width="60px">&nbsp;
					</td>
					<td align="left">
					        <input type="file" name="uploadFile" id="uploadify" />
					        <input name="userVcard.avatar" type="hidden" id="user_avatar_id" size="30" value="" />
					        <input name="userId" type="hidden" id="user_userId_id" size="30" value="" />
					</td>
				</tr>
	
				<tr>
					<td width="80px">姓名：</td>
					<td>
						<input name="userVcard.name" size="30" value="" id="user_name_id" class="input_1 required" />
					</td>
				</tr>
	
				<tr>
					<td>手机号：</td>
					<td>
						<input name="username" value="" id="user_userName_id"  class="input_1 required validate-mobile-phone" />
					</td>
				</tr>
	
				<tr>
					<td>重置密码：</td>
					<td>
						<input name="password" value="" id="user_password_id" class="input_1 required" />
					</td>
				</tr>
	
				<tr>
					<td>性别：</td>
					<td align="left">
						<select class="select_1 required" id="user_sex_id" name="userVcard.sex">
								<option value="0">男</option>
								<option value="1">女</option>
						</select>
					</td>
				</tr>
	
				<tr>
					<td>工号：</td>
					<td align="left">
						<select class="select_1 required" id="user_number_id" name="userVcard.number">
								<option>00001</option>
								<option>00002</option>
						</select>
					</td>
				</tr>
	
				<tr>
					<td>部门：</td>
					<td align="left">
						<select class="select_1 required" id="user_dep_id" name="userVcard.dep">
								<option>财务部</option>
								<option>研发部</option>
						</select>
					</td>
				</tr>
	
				<tr>
					<td>职务：</td>
					<td align="left">
						<select class="select_1 required" id="user_position_id" name="userVcard.position">
								<option>总经理</option>
								<option>工程师</option>
						</select>
					</td>
				</tr>
	
				<tr>
					<td>&nbsp;</td>
					<td align="left"><input type="button" id="add_user_btn_id" value="修改" class="btn_3"
						style="margin-top: 15px" /></td>
				</tr>
			</table>
		</form>
	</div>
	<script>
		
	
		$(function(){
			var userId = $.request.queryString["userId"];
			jQuery.ajax({
				type : 'Get',
				contentType : 'application/json',
				url : '../user/get.do',
				data : {
					userId : userId 
				},
				dataType : 'json',
				success : function(data) {
					if (data.result) {
						var userVcard = data.obj.userVcard;
						$.each(userVcard,function(key,value){
							var elmId = "#user_"+key+"_id";
							$(elmId).val(value);
							if(key == "avatar"){
								$('#head_pic_id').attr("src",value);
							}
						});
						//$('#user_password_id').val(data.obj.password);
						$('#user_userId_id').val(data.obj.userId);
					} else {
						alert('数据库异常,查询数据失败');
					}
				},
				error : function(data) {
					alert("error")
				}
			});	
			var valid = new Validation('user_form_id',{immediate:true},{onSubmit:false});
			$('#add_user_btn_id').click(
				function(){
					var result = valid.validate();
					if(!result){
						return;
					}
					
					if($("#user_avatar_id").val() == ""){
						alert("请上传头像");
						return;
					}
					var formData = $('#user_form_id').serialize();
					jQuery.ajax( {
						type : 'POST',
						url : '../user/edit.do',
						dataType : 'json',
						data : formData,
						success : function(obj) {
							if(obj.result){
								alert("保存数据成功");
								location.href="./userList.html";
							}else{
								alert(obj.errorMsg);
							}
						},
						error : function() {
							alert('error');
						}
					});
				}		
			);
			
			//上传图片
			$("#uploadify").uploadify({
				height        : 30,
				swf           : '../styles/uploadify.swf',
				uploader      : '../upload/add.do?jSessionid=9B16F7330BD01F6C96CB79971F36EA2B',
				buttonText    : '上传头像',  
				width         : 100,
				cancelImg     : '../images/uploadify-cancel.png',
				uploadLimit   : 6, 
				onUploadSuccess:function(file, data, response){  
					var dataObj = eval("("+data+")");
	            	$('#head_pic_id').attr("src",dataObj.obj.httpPath+"/upload/download.do?fileName="+dataObj.obj.name);
	            	$('#user_avatar_id').val(dataObj.obj.httpPath+"/upload/download.do?fileName="+dataObj.obj.name);
	        	},  
	        	onUploadStart : function(file) {
	        		autoIframe();
	        	}, 
				onInit: function () {
	        		var ie = !-[1,];
	        		//载入时触发，如果是IE将flash设置到最小	
	    			if(ie){
	    				$("#uploadify-queue").hide();	
	    			}
	            }
			});
		});
		
		
	</script>
</body>
</html>